

//select
function selectall(name){
	$("input[name='"+name+"']").each(function(){
		$(this).attr("checked",true);
	});
}

//select
function unselectall(name){
	$("input[name='"+name+"']").each(function(){
		$(this).attr("checked",false);
	});
}

//select
function getRadioValue(name){
	var val="";
	$("input[name='"+name+"']").each(function(){
		if($(this).attr("checked")){
			val=$(this).val();
		}
	});
	return val;
}
//select
function getCheckboxValue(name){
	var val="";
	$("input[name='"+name+"']").each(function(){
		if($(this).attr("checked")){
			if(val==""){
				val=$(this).val();
			}else{
				val=val+","+$(this).val();
			}
		}
	});
	return val;
}
//select
function getCheckboxAllValue(name){
	var val="";
	$("input[name='"+name+"']").each(function(){
		if($(this).attr("checked")){
			if(val==""){
				val=$(this).val();
			}else{
				val=val+","+$(this).val();
			}
		}else{
			if(val==""){
				val="false";
			}else{
				val=val+",false";
			}
		}
	});
	return val;
}
//input
function getInputValue(name,sp){
	var val="";
	$("input[name='"+name+"']").each(function(){
		if(val==""){
			val=$(this).val();
		}else{
			val=val+sp+$(this).val();
		}
	});
	return val;
}

//select
function setRadioValue(name,val){
	$("input[name='"+name+"']").each(function(){
		if(val==$(this).val()){
			$(this).attr("checked",true);
		}else{
			$(this).attr("checked",false);
		}
	});
}
//select
function setCheckboxValue(name,val){
	var vals=val.split(",");
	$("input[name='"+name+"']").each(function(){
		var v=$(this).val();
		var flag=0;
		for(var i=0;i<vals.length;i++){
			if(v==vals[i]){
				flag=1;
				break;
			}
		}
		if(flag==1){
			$(this).attr("checked",true);
		}else{
			$(this).attr("checked",false);
		}
	});
}


//ajax
var ajax_name="";
function ajax(name,param,pagename,page){
	$(document).ready(function() { 
		ajax_name=name;
		$("#"+name).ajax(param,pagename,page);
	});
}
function ajaxreload(name){
	if(name==""){
		name=ajax_name;
	}
	$("#"+name).ajaxreload();
}
function ajaxnext(name,pages){
	if(name==""){
		name=ajax_name;
	}
	$("#"+name).ajaxnext(pages);
}
function ajaxpre(name){
	if(name==""){
		name=ajax_name;
	}
	$("#"+name).ajaxpre();
}
function ajaxpage(name,page){
	if(name==""){
		name=ajax_name;
	}
	$("#"+name).ajaxpage(page);
}
function ajaxparam(name,param){
	if(name==""){
		name=ajax_name;
	}
	$("#"+name).ajaxparam(param);
}
//ajax end

function reloadAjax(){
	ajaxreload("");
}
function reloadAjax1(name){
	ajaxreload(name);
}

function toUrl(url){
	location.href=url;
}

function showSuccess(id){
	atSuccess("操作成功");
}


function openwin(url,name){
	if(name==undefined||name==""){
		window.open(url);
	}else{
		window.open(url, name);
	}
}




var fileload=0;
function doCommonUpload(ispic){
	fileload=0;
	var name="img";
	var img=$("#"+name).val();
	var ext=getExt(img).toLowerCase();
	if(ispic=="false"||(ext=="png"||ext=="jpg"||ext=="gif")){
		atPage("",base+"/upload",'file='+name+'&ispic='+ispic,300,60,false,"upload",19998);
	}else{
		parent.atInfo("请选择图片上传!");
	}	
}
function doAddFile(data){
	var flag=data["flag"];
	var name=data["name"];
	var no=data["no"];
	var filename=data["filename"];
	var url=data["url"];
	var path=data["path"];
	var fun=data["fun"];
	try{
		uploadProgressReturn(100);
		uploadCallBack(filename,no,url,name,path);
	}catch(e){}
}

function uploadProgressReturn(flag){
	fileload=flag;
}
function getFileLoad(){
	return fileload;
}

function getExt(name){
var ext=name.substring(name.lastIndexOf(".")+1);
return ext;
}


 function showLeft(){
  	document.getElementById("navHide").style.display="none";
	document.getElementById("navShow").style.display="block";
	document.getElementById("left_body").style.display="none";
	document.getElementById("right_body").className="content_960";
	showHideLeft(1);
  }
  function hideLeft(){
  	document.getElementById("navHide").style.display="block";
	document.getElementById("navShow").style.display="none";
	document.getElementById("left_body").style.display="block";
	document.getElementById("right_body").className="content_main";
	showHideLeft(0);
  }
function showHideLeft(flag){
	var param=new Object();
	param["flag"]=flag;
	submitCommon(param,"showHideLeft","doShowHideLeft");
}
function doShowHideLeft(data){
}
function initShowHideLeft(){
	var param=new Object();
	submitCommon(param,"initShowHideLeft","doInitShowHideLeft");
}
function doInitShowHideLeft(data){
	var flag=data["flag"];
	if(flag==1){
		document.getElementById("navHide").style.display="none";
		document.getElementById("navShow").style.display="block";
		document.getElementById("left_body").style.display="none";
		document.getElementById("right_body").className="content_960";
	}else{
		document.getElementById("navHide").style.display="block";
		document.getElementById("navShow").style.display="none";
		document.getElementById("left_body").style.display="block";
		document.getElementById("right_body").className="content_main";
	}
}
function showHideFilesCore(id){
	var sid=$("#sid").val();
	var param=new Object();
	param["id"]=id;
	param["sid"]=sid;
	submitCommon(param,"showHideFilesCore","doShowHideFilesCore");
}
function doShowHideFilesCore(data){
	var flag=data["flag"];
	if(flag==1){
		$("#show_flag").show();
	}else{
		$("#files").val("");
		$("#show_files").html("");
		$("#show_flag").hide();
	}
}

function toPos(id){
	var pos = $(id).offset().top-40; 
	$("html,body").animate({scrollTop: pos}, 500);
}

function getCurrentPage(num){
	var result=1;
	if(num%20==0){
		result=parseInt(num/20);
	}else{
		result=parseInt(num/20)+1;
	}
	return result;
}

function leftHeight(){
	try{
		var h=$("#left_body").height();
		var h1=$("#right_body").height()-60;
		if(h1>h){
			$("#left_body").height(h1);
		}
	}catch(e){}
}

function parseName(name){
	var result=name;
	var index=name.lastIndexOf("\\");
	if(index!=-1){
		result=name.substring(index+1);
	}
	return result;
}


/**
 * 得到ajax对象
 */
function getajaxHttp() {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("您的浏览器不支持AJAX！");
				return false;
			}
		}
	}
	return xmlHttp;
}
/**
 * 发送ajax请求
 * url--url
 * methodtype(post/get)
 * con (true(异步)|false(同步))
 * parameter(参数)
 * functionName(回调方法名，不需要引号,这里只有成功的时候才调用)
 * (注意：这方法有二个参数，一个就是xmlhttp,一个就是要处理的对象)
 * obj需要到回调方法中处理的对象
 */
function ajaxrequest(url,methodtype,con,parameter,functionName,obj){
	var xmlhttp=getajaxHttp();
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4){
			//HTTP响应已经完全接收才调用
			functionName(xmlhttp,obj);
		}
	};
	xmlhttp.open(methodtype,url,con);
	xmlhttp.send(parameter);
}
